<template>
<div class="daily_recom_cp">   
    <div class = "container my_box_shadow my_div_radius text_color">
        <div class="title">
            <i class="el-icon-reading"></i>
            精选好文
        </div>
        <div 
            class="content" 
            v-if="dataList.length>0">
            <a  
                class="my_div_radius"
                v-for="essay in dataList" 
                :key="essay.id" 
                @click="onClick(essay.id)">
                {{essay.name}}
            </a>
        </div>
        <div 
            v-else 
            class="content content_loading" 
            style="color: rgb(243, 69, 115);">
            <i class="el-icon-loading"></i>
        </div>
    </div>
</div> 
</template>
<script>
export default {  //每日推荐短文列表
    name:'DailyRecomCp',
    data(){
        return{
            dataList:[],
        };
    },
    methods:{
        getRecommendEssays(){  //获取推荐的短文
            this.$axios.$Api.getRecommendEssays({
                number:10,
            }).then((data)=>{	
                this.dataList=data;
            });
        },
        onClick(essayId){  //item被点击后触发的属性
            this.$emit("onClick",essayId);
        },
    },
    created(){
        if(!process.client) return;
        if(this.dataList.length>0) return;
        this.getRecommendEssays();
    },
}
</script>
<style lang='scss' scoped>
.daily_recom_cp{
    width: 100%;
    height: fit-content;
    background-color:#ffffff;
    >.container{
        >.title{
            font-size: 14px;
            line-height: 1;
            letter-spacing:1px;
            text-align:start !important; 
            padding: 15px;
            box-sizing: border-box;
            border-bottom: 1px solid #f6f6f6;
            /deep/i{
                margin-right:5px;
                color: rgb(243, 69, 115);
            }
        }
        >.content{
            display: flex;
            flex-direction: row;
            flex-wrap:wrap;
            justify-content:flex-start;
            align-items:flex-start;
            padding: 7.5px;
            >a{
                cursor:Pointer;
                font-size: 12px;
                line-height: 1.5;
                letter-spacing:1.5px;
                text-align: left;
                margin: 7.5px;
                background: #f5f5f5;
                padding: 7px 9px;
                opacity:0.9;
                transition: color 0.2s,border 0.2s;
                border: solid 1.5px #fbfbfb00;
                &:hover { 
                    color: #e42c64;
                    border: solid 1.5px #ffd966;
                }
            }
        }
        >.content_loading{
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            text-align: center;
            padding: 5px;
        }
    }
}
</style>